package it.unipr.ce.dsg.deus.automator.gui;

import it.unipr.ce.dsg.deus.automator.Runner;
import java.awt.event.ActionEvent;
import javax.swing.UIManager;


/**
 * 
 * @author Marco Picone (picone.m@gmail.com)
 * 
 */
@SuppressWarnings("serial")
public class SimulationSummaryFrame extends javax.swing.JFrame {

	private boolean isStart = false;
	private boolean isClose = false;
	private Runner runner = null;

	/**
	 * Creates new form SimulationSummaryFrame
	 * 
	 * @param runner
	 */
	public SimulationSummaryFrame(Runner runner) {
		initComponents();
		this.runner = runner;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		this.setTitle("Deus Automator - Simulation Summary");
		/*
		 * Set the better look and feel for the running platform
		 */
		// Default System
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e1) {
			// Win32
			try {
				UIManager
						.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			} catch (Exception e2) {
				// Linux gtk
				try {
					UIManager
							.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
				} catch (Exception e3) {
					// MacOS
					try {
						UIManager
								.setLookAndFeel("javax.swing.plaf.mac.MacLookAndFeel");
					} catch (Exception e4) {
						try {
							// Cross platform metal
							UIManager.setLookAndFeel(UIManager
									.getCrossPlatformLookAndFeelClassName());
						} catch (Exception e5) {
							e5.printStackTrace();
							System.exit(1);
						}
					}
				}
			}

		}

		dsgLogoLabel = new javax.swing.JLabel();
		simulationSummaryScrollPane = new javax.swing.JScrollPane();
		simulationSummaryTextArea = new javax.swing.JTextArea();
		startButton = new javax.swing.JButton();
		closeButton = new javax.swing.JButton();

		dsgLogoLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
		dsgLogoLabel.setForeground(new java.awt.Color(204, 0, 0));
		dsgLogoLabel.setIcon(new javax.swing.ImageIcon(
				("res/dsgLogo_noBack_small.png"))); // NOI18N
		dsgLogoLabel.setText(" - Deus Automator - Simulation Summary");

		simulationSummaryTextArea.setBackground(new java.awt.Color(0, 0, 0));
		simulationSummaryTextArea.setColumns(20);
		simulationSummaryTextArea.setEditable(false);
		simulationSummaryTextArea.setForeground(new java.awt.Color(255, 255,
				255));
		simulationSummaryTextArea.setRows(5);
		simulationSummaryScrollPane.setViewportView(simulationSummaryTextArea);

		startButton.setText("Start");
		startButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				startButtonActionPerformed(evt);
			}
		});

		closeButton.setText("Close");
		closeButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				closeButtonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addComponent(
																		closeButton)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(
																		startButton))
												.addComponent(
														simulationSummaryScrollPane,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														410, Short.MAX_VALUE)
												.addComponent(dsgLogoLabel))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(dsgLogoLabel)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addComponent(simulationSummaryScrollPane,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										237, Short.MAX_VALUE)
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(closeButton)
												.addComponent(
														startButton,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														23,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addContainerGap()));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	protected void closeButtonActionPerformed(ActionEvent evt) {
		this.isClose = true;
		this.dispose();
	}

	protected void startButtonActionPerformed(ActionEvent evt) {
		this.isStart = true;

		new Thread(new Runnable() {
			public void run() {
				runner.runSimulations();
			}
		}).start();

		this.dispose();
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton closeButton;
	private javax.swing.JLabel dsgLogoLabel;
	private javax.swing.JScrollPane simulationSummaryScrollPane;
	private javax.swing.JTextArea simulationSummaryTextArea;
	private javax.swing.JButton startButton;
	// End of variables declaration//GEN-END:variables

	public boolean isStart() {
		return isStart;
	}

	public void setStart(boolean isStart) {
		this.isStart = isStart;
	}

	public boolean isClose() {
		return isClose;
	}

	public void setClose(boolean isClose) {
		this.isClose = isClose;
	}

	public javax.swing.JTextArea getSimulationSummaryTextArea() {
		return simulationSummaryTextArea;
	}

	public void setSimulationSummaryTextArea(
			javax.swing.JTextArea simulationSummaryTextArea) {
		this.simulationSummaryTextArea = simulationSummaryTextArea;
	}

}
